home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / tn3270 / apistg.c < prev    next >
Text File  |  1992-04-17  |  6KB  |  257 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.4d7  April, 1992
  5.  *  Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #if !defined(USEDUMP)
  34.     #include "maclib.h"
  35.     #include "termdef.h"
  36.     #include "tn3270funcs.h"
  37.     #include "globals.h"
  38. #else
  39.     #pragma load "tn3270DumpFile"
  40. #endif
  41.  
  42. #pragma segment api
  43.  
  44. #define PARAMNEEDED        5
  45. #define CLIENTNEEDED    2
  46. #define DATANEEDED        5        
  47.  
  48. void initparamblocks(void)
  49. {
  50. memset(¶mqueue, 0, sizeof(queueinfo));
  51. strcpy(paramqueue.name, "Param");
  52. paramqueue.elemsize = sizeof(paramrec);
  53. paramqueue.minavail = PARAMNEEDED;
  54. }
  55.  
  56. void initclientrecs(void)
  57. {
  58. memset(&clientqueue, 0, sizeof(queueinfo));
  59. strcpy(clientqueue.name, "Client");
  60. clientqueue.elemsize = sizeof(clientrec);
  61. clientqueue.minavail = CLIENTNEEDED;
  62. }
  63.  
  64. void initdatablocks(void)
  65. {
  66. memset(&dataqueue, 0, sizeof(queueinfo));
  67. strcpy(dataqueue.name, "Data");
  68. dataqueue.elemsize = sizeof(datarec);
  69. dataqueue.minavail = DATANEEDED;
  70. }
  71.  
  72. void endparamblocks(void)
  73. {
  74. endqueue(¶mqueue);
  75. }
  76.  
  77. void endclientrecs(void)
  78. {
  79. endqueue(&clientqueue);
  80. }
  81.  
  82. void enddatablocks(void)
  83. {
  84. endqueue(&dataqueue);
  85. }
  86.  
  87. void endqueue(queueinfo *qp)
  88. {
  89. qctl *current, *next;
  90.  
  91. next = qp->first;
  92. while (next != 0) {
  93.     current = next;
  94.     next = (qctl *)current->next;
  95.     DisposPtr((Ptr)current);
  96.     }
  97. qp->first = 0;
  98. qp->stgerr = 0;
  99. qp->spare = 0;
  100. }
  101.  
  102. void addparamblocks(void)
  103. {
  104. addqueue(¶mqueue);
  105. }
  106.  
  107. void addclientrecs(void)
  108. {
  109. addqueue(&clientqueue);
  110. }
  111.  
  112. void adddatablocks(void)
  113. {
  114. addqueue(&dataqueue);
  115. }
  116.  
  117. void addqueue(queueinfo *qp)
  118. {
  119. qctl *current;
  120. short avail, i, needed;
  121. OSErr rc;
  122. /* unsigned char msg[120];  ****** */
  123.  
  124. if (qp->stgerr) return;
  125.  
  126. avail = 0;
  127. current = qp->first;
  128. while (current != 0) {
  129.     if (current->inuse == 0) {
  130.         avail++;        
  131.         }
  132.     current = (qctl *)current->next;
  133.     }
  134.  
  135. /*  queue debugging code  ********
  136. if (avail != qp->spare) {
  137.     sprintf(msg, "Queue %s: avail was %d, now %d", qp->name, qp->spare, avail);
  138.     cs.dblevel = 1;
  139.     dbdlg(msg);
  140.     cs.dblevel = 0;
  141.     qp->spare = avail;
  142.     }                     ******** */
  143.  
  144. needed = qp->minavail - avail;
  145. if (needed <= 0) return;
  146. for (i = 0; i < needed; i++) {
  147.     rc = extendqueue(qp);
  148.     if (rc != noErr) break;
  149.     }
  150. if (rc != noErr) qp->stgerr = 1;
  151. }
  152.  
  153. OSErr extendqueue(queueinfo *qp)
  154. {
  155. qctl *new, *current;
  156.  
  157. new = (qctl *)myNewPtr(qp->elemsize, 0);
  158. if (new == 0) {
  159.     return(mFulErr);
  160.     }
  161. memset(new, 0, qp->elemsize);
  162. if (qp->first == 0) {
  163.     qp->first = new;
  164.     return(noErr);
  165.     }
  166. current = qp->first;
  167. while (current->next != 0) {
  168.     current = (qctl *)current->next;
  169.     }
  170. current->next = (unsigned char *)new;
  171. return(noErr);
  172. }
  173.  
  174. PPCParamBlockPtr newparamblock(void)
  175. {
  176. paramrec * prp;
  177.  
  178. prp = (paramrec *)getnew(¶mqueue);
  179. if (prp == 0) return(0);
  180. else return(&(prp->pb));
  181. }
  182.  
  183. clientinfo * newclientrec(void)
  184. {
  185. clientrec * crp;
  186.  
  187. crp = (clientrec *)getnew(&clientqueue);
  188. if (crp == 0) return(0);
  189. else return(&(crp->client));
  190. }
  191.  
  192. datainfo * newdatablock(void)
  193. {
  194. datarec * drp;
  195.  
  196. drp = (datarec *)getnew(&dataqueue);
  197. if (drp == 0) return(0);
  198. else return(&(drp->data));
  199. }
  200.  
  201. qctl * getnew(queueinfo *qp)
  202. {
  203. qctl *current;
  204.         /* Note: this code is designed so that if it is interrupted
  205.            by a copy of itself running at interrupt level, it will
  206.            not allocated the same element twice. */
  207. current = qp->first;
  208. while (current != 0) {
  209.     if (current->inuse == 0) {
  210.         if (current->pend_inuse == 0) {
  211.             current->pend_inuse == 1;
  212.             if (current->inuse == 0) {
  213.                 current->inuse = 1;
  214.                 current->pend_inuse = 0;
  215.                 return(current);
  216.                 }
  217.             else {
  218.                 current->pend_inuse = 0;
  219.                 }
  220.             }
  221.         }
  222.     current = (qctl *)current->next;
  223.     }
  224. return(0);
  225. }
  226.  
  227. void disposparamblock(PPCParamBlockPtr p)
  228. {
  229. disposelem((unsigned char *)p, ¶mqueue);
  230. }
  231.  
  232. void disposclientrec(clientinfo *p)
  233. {
  234. disposelem((unsigned char *)p, &clientqueue);
  235. }
  236.  
  237. void disposdatarec(datainfo *p)
  238. {
  239. disposelem((unsigned char *)p, &dataqueue);
  240. }
  241.  
  242. void disposelem(unsigned char *s, queueinfo *qp)
  243. {
  244. qctl * delete_elem, *current;
  245.  
  246. s -= sizeof(qctl);
  247. delete_elem = (qctl *)s;
  248. current = qp->first;
  249. while (current != 0) {
  250.     if (current == delete_elem) {
  251.         current->inuse = 0;
  252.         return;
  253.         }
  254.     current = (qctl *)current->next;
  255.     }
  256. }
  257.